# -*- coding: utf8 -*-
import requests
import time

#改密替换参数
RK = 'mTyNBK1md7'
uid = '172819954'
vappid = '11059694'
g_vstk = '1275659506'
g_actk = '1362282891'
pgv_pvi = '1826720768'
vqq_appid = '101483052'
pgv_pvid = '9716079200'
vqq_vuserid ='121819358'
pgv_info = 'ssid=s6960688994'
video_guid = 'e422961fdfc82282'
tvfe_boss_uuid = '6b841fa1ab18f122'
vqq_vusession = 'W9PiLklQBPJenRjhUUFiQw..'
vqq_openid = '8DCACB14C285E718D35FB890AC8CED39'
vqq_access_token = '0F64BD8883AFC9D48B766D57FD6C8738'
vqq_refresh_token = '6A34AF98587A74D558E63A891282CBEE'
vsecret = 'fdf61a6be0aad57132bc5cdf78ac30145b6cd2c1470b0cfe'
callback = 'jQuery191029948243322864987_1585273379427&_=1585273379428'
ptcz = '78764f1ac97194df261292340e8ac493003a58b59905b2d8daec2989dfad3655'

def start():
    try:
        login_headers = {'Referer': 'https://v.qq.com','Cookie': 'pgv_pvi='+pgv_pvi+';ptui_loginuin=517070702; RK='+RK+'; ptcz='+ptcz+'; tvfe_boss_uuid='+tvfe_boss_uuid+'; video_guid='+video_guid+'; video_platform=2; pgv_pvid='+pgv_pvid+'; main_login=qq; vqq_access_token='+vqq_access_token+'; vqq_appid='+vqq_appid+'; vqq_openid='+vqq_openid+'; vqq_vuserid='+vqq_vuserid+'; vqq_refresh_token='+vqq_refresh_token+'; vqq_vusession='+vqq_vusession+'; pgv_info='+pgv_info+'; uid='+uid+';'
}
        login = requests.get('https://access.video.qq.com/user/auth_refresh?vappid='+vappid+'&vsecret='+vsecret+'&type=qq&g_tk=&g_vstk='+g_vstk+'&g_actk='+g_actk+'&callback='+callback,headers=login_headers)

        cookie = requests.utils.dict_from_cookiejar(login.cookies)

        sign_headers = {
            'Cookie': 'pgv_pvi='+pgv_pvi+'; ptui_loginuin=517070702; RK='+RK+'; ptcz='+ptcz+'; tvfe_boss_uuid='+tvfe_boss_uuid+'; video_guid='+video_guid+'; video_platform=2; pgv_pvid='+pgv_pvid+'; main_login=qq; vqq_access_token='+vqq_access_token+'; vqq_appid='+vqq_appid+'; vqq_openid='+vqq_openid+'; vqq_vuserid='+vqq_vuserid+'; vqq_refresh_token='+vqq_refresh_token+'; vqq_vusession='+cookie['vqq_vusession']+';'}
        res = requests.get('https://vip.video.qq.com/fcgi-bin/comm_cgi?name=hierarchical_task_system&cmd=2',headers=sign_headers).text
        
        print(res)
        
        if 'Account Verify Error' in res:
            print('cookies失效！')
            requests.get('https://sc.ftqq.com/SCU54227T9cef98d441454319935c5b76f8bd49545d136637ac860.send' + '?text= 腾讯视频自动签到失败_'+time.strftime('%Y.%m.%d',time.localtime(time.time())) +'&desp='+'cookies失效，请更新')
        else:
            print('签到完成！')
            requests.get('https://sc.ftqq.com/SCU54227T9cef98d441454319935c5b76f8bd49545d136637ac860.send' + '?text= 腾讯视频自动签到成功_'+time.strftime('%Y.%m.%d',time.localtime(time.time())) +'&desp='+ res)
    except Exception as e:
        print("地址访问失败！")
        requests.get('https://sc.ftqq.com/SCU54227T9cef98d441454319935c5b76f8bd49545d136637ac860.send' + '?text= 腾讯视频自动签到失败_'+time.strftime('%Y.%m.%d',time.localtime(time.time())) +'&desp='+'异常代码：\n'+str(e))

def main_handler(event, context):
    return start()
if __name__ == '__main__':
    start()